package com.ruoyi.jiuzai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.jiuzai.domain.RAR;
import com.ruoyi.jiuzai.domain.Wuzileibie;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jiuzai.domain.Wuzixinxi;
import com.ruoyi.jiuzai.service.IWuzixinxiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-19
 */
@RestController
@RequestMapping("/jiuzai/wuzixinxi")
public class WuzixinxiController extends BaseController {
    @Autowired
    private IWuzixinxiService wuzixinxiService;

    /**
     * 查询物资信息列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzixinxi:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wuzixinxi wuzixinxi) {
        startPage();
        List<Wuzixinxi> list = wuzixinxiService.selectWuzixinxiList(wuzixinxi);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出物资信息列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzixinxi:export')")
    @Log(title = "物资信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wuzixinxi wuzixinxi) {
        List<Wuzixinxi> list = wuzixinxiService.selectWuzixinxiList(wuzixinxi);
        ExcelUtil<Wuzixinxi> util = new ExcelUtil<Wuzixinxi>(Wuzixinxi.class);
        util.exportExcel(response, list, "物资信息数据");
    }

    /**
     * 获取物资信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzixinxi:query')")
    @GetMapping(value = "/{wuziId}")
    public AjaxResult getInfo(@PathVariable("wuziId") Long wuziId) {
        return success(wuzixinxiService.selectWuzixinxiByWuziId(wuziId));
    }

    /**
     * 新增物资信息
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzixinxi:add')")
    @Log(title = "物资信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wuzixinxi wuzixinxi) {
        return toAjax(wuzixinxiService.insertWuzixinxi(wuzixinxi));
    }

    /**
     * 修改物资信息
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzixinxi:edit')")
    @Log(title = "物资信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wuzixinxi wuzixinxi) {
        return toAjax(wuzixinxiService.updateWuzixinxi(wuzixinxi));
    }

    /**
     * 删除物资信息
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuzixinxi:remove')")
    @Log(title = "物资信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wuziIds}")
    public AjaxResult remove(@PathVariable Long[] wuziIds) {
        return toAjax(wuzixinxiService.deleteWuzixinxiByWuziIds(wuziIds));
    }

    @PreAuthorize("@ss.hasPermi('jiuzai:wuzixinxi:name')")
    @GetMapping("/name")
    public RAR chaName() {
        List<Wuzileibie> wuzileibies = wuzixinxiService.chaName();
        return new RAR(200, "成功", wuzileibies);
    }

    @PreAuthorize("@ss.hasPermi('jiuzai:wuzixinxi:listWithLeibie')") // 添加权限控制
    @GetMapping("/listWithLeibie")
    public TableDataInfo listWithLeibie(Wuzixinxi wuzixinxi) {
        List<Wuzixinxi> list = wuzixinxiService.selectWuzixinxiListWithLeibie(wuzixinxi);
        System.out.println(list);
        return getDataTable(list);
    }
}
